SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
-- Crea vista afiliacion
-- drop view afiliacion

CREATE VIEW [dbo].[afiliacion] AS
SELECT	a.Documento AS pers_documento,
		CASE a.Sexo
			WHEN 1 THEN 'F'
			WHEN 2 THEN 'M'
		END AS pers_sexo,
		o.idOrganismo AS organismo_id,
		af.NumeroAfiliado AS afiliacion_nro_afiliado,
		af.FechaInicioAportes AS afiliacion_fecha_desde,
		af.MontoMensual AS afiliacion_importe
FROM	tb_Afiliaciones af 
		LEFT JOIN tb_Agentes a ON (af.idAgente = a.idAgente) 
		LEFT JOIN tb_Organismos o ON (af.Organismo = o.idOrganismo)


/*
30950
select * from tb_afiliaciones
select count(*) from RRHH_15..AFILIACION

select * from tb_organismos where idorganismos=1
select * from tb_suborganizaciones where organismo_id_sarrhh=13
*/
GO
